//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Validation Application Block
//===============================================================================
// Code file original author: Martin Lapierre, http://devinstinct.com
//===============================================================================

using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace EntLibContrib.Validation.Validators
{
	/// <summary>
	/// Provides pre-allocated, thread-safe validators.
	/// </summary>
	public static class DefaultValidators
	{
		#region Fields
		/// <summary>
		/// Validates that objects references are not null using, the default ruleSet.
		/// </summary>
		private static NotNullValidator notNullValidator = new NotNullValidator();

		/// <summary>
		/// Validates that objects references are null using, the default ruleSet.
		/// </summary>
		private static NotNullValidator nullValidator = new NotNullValidator(true);

		/// <summary>
		/// Validates that strings are neither null nor empty, using the default ruleSet.
		/// </summary>
		private static AndCompositeValidator stringNotNullNorEmptyValidator = new AndCompositeValidator(DefaultValidators.NotNullValidator, new StringLengthValidator(0, RangeBoundaryType.Exclusive, int.MaxValue, RangeBoundaryType.Inclusive));

		/// <summary>
		/// Validates that collections are neither null nor empty, using the default ruleSet.
		/// </summary>
		private static AndCompositeValidator collectionNotNullNorEmptyValidator = new AndCompositeValidator(DefaultValidators.NotNullValidator, new CollectionCountValidator(0, RangeBoundaryType.Exclusive, int.MaxValue, RangeBoundaryType.Inclusive));

		/// <summary>
		/// Validates that the value is Defined in the enum's values.
		/// </summary>
		private static EnumDefinedValidator enumDefinedValidator = new EnumDefinedValidator();

		/// <summary>
		/// Validates that the value is not Defined in the enum's values.
		/// </summary>
		private static EnumDefinedValidator enumNotDefinedValidator = new EnumDefinedValidator(true);
		#endregion

		#region Properties
		/// <summary>
		/// Gets the not null validator.
		/// </summary>
		/// <value>The not null validator.</value>
		public static NotNullValidator NotNullValidator
		{
			get { return notNullValidator; }
		}

		/// <summary>
		/// Gets the null validator.
		/// </summary>
		/// <value>The null validator.</value>
		public static NotNullValidator NullValidator
		{
			get { return nullValidator; }
		}

		/// <summary>
		/// Gets the string not null nor empty validator.
		/// </summary>
		/// <value>The string not null nor empty validator.</value>
		public static AndCompositeValidator StringNotNullNorEmptyValidator
		{
			get { return stringNotNullNorEmptyValidator; }
		}

		/// <summary>
		/// Gets the collection not null nor empty validator.
		/// </summary>
		/// <value>The collection not null nor empty validator.</value>
		public static AndCompositeValidator CollectionNotNullNorEmptyValidator
		{
			get { return collectionNotNullNorEmptyValidator; }
		}

		/// <summary>
		/// Gets the enum defined validator.
		/// </summary>
		/// <value>The enum defined validator.</value>
		public static EnumDefinedValidator EnumDefinedValidator
		{
			get { return enumDefinedValidator; }
		}

		/// <summary>
		/// Gets the enum not defined validator.
		/// </summary>
		/// <value>The enum not defined validator.</value>
		public static EnumDefinedValidator EnumNotDefinedValidator
		{
			get { return enumNotDefinedValidator; }
		}
		#endregion
	}
}
